#include "stdafx.h"
#include "Sun.h"


Sun::Sun(void)
{
}
Sun::Sun(int width, int height, int tWidth, int tHeight)
{
	angle = 0;
	ticker = 2500;
	textureWidth = tWidth;
	textureHeight = tHeight;
	G = gluNewQuadric();
	gluQuadricDrawStyle(G,GLU_FILL);
	gluQuadricOrientation(G, GLU_OUTSIDE);
	eye = Eye(-(float) tWidth*5, (float) tHeight/2, 0.0f);
	setupLightSource();

}

void Sun::setMatrix(){

}

void Sun::tick(){
	ticker++;
	if (ticker == 3600){
		angle = (angle + 36) % 360;
		float hypothenuse =		(float) 5 * textureWidth;
		float x =				(float) -hypothenuse * sin(angle);
		float y =				(float) (hypothenuse * sin(360-angle));
		eye.X = x;
		eye.Y = y;
		GLfloat light_position[] = { eye.X, eye.Y, eye.Z, 0.0f };
		glLightfv(GL_LIGHT0, GL_POSITION, light_position);
		ticker = 0;
	}
}

void Sun::draw(){
	tick();
	glPushMatrix();
	glEnable(GL_COLOR_MATERIAL);
	glColor3f(1.0f, 1.0f, 0.0f);
	glTranslatef(-eye.X, -eye.Y, eye.Z);
	gluSphere(G,4,10,10); 
	glDisable(GL_COLOR_MATERIAL);
	glPopMatrix();
}


void Sun::setupLightMatrix(){

}
void Sun::setupLightSource(){
	GLfloat light_ambient[] = { 0.2, 0.2, 0.2, 1};
	GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
	GLfloat light_position[] = { -eye.X, -eye.Y, -eye.Z, 0.0f };
	GLfloat light_specular[] = { 1,1,1,1 };

	glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
	glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
	glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
	glLightfv(GL_LIGHT0, GL_POSITION, light_position);

	glEnable(GL_LIGHT0);
}
Sun::~Sun(void)
{
}
